import React, { useState, useEffect } from 'react'
import { View, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { AtForm, AtInput, AtButton } from 'taro-ui'

import './index.less'
import "taro-ui/dist/style/components/input.scss";
import "taro-ui/dist/style/components/icon.scss";
import ToLogin from '../../compontents/toLogin'
import api from '../../http/api'


export default (props: any) => {
  const [value1,setValue1] = useState('')
  const [value2,setValue2] = useState('')
  const [value3,setValue3] = useState('')
  const [value4,setValue4] = useState('')
  const info: any = Taro.getStorageSync('info')
  const  uSchoolId  = info?JSON.parse(info).userInfo.uSchoolId:0
  const onSubmit = (e:any) => {
    if(value1&&value2&&value3&&value4){
      api.businessInsert({
        name:value1,
        tel:value2,
        businessName:value3,
        address:value4,
        uSchoolId
      }).then(_=>{

        Taro.showModal({
          title: '提示',
          content: '恭喜您入驻成功，稍后将有工作人员联系您。',
          complete: function (res) {
            Taro.navigateBack({
              delta: 1
            })
          }
        })
      })
      
      
    }else{
      Taro.showToast({
        title: '请填写完整信息',
        icon: 'none'
      })
    }
  }
  const onChange1 = (e) => {
    setValue1(e)
  }
  const onChange2 = (e) => {
    setValue2(e)
  }
  const onChange3 = (e) => {
    setValue3(e)
  }
  const onChange4 = (e) => {
    setValue4(e)
  }
  return (
    <View className='business'>
     <ToLogin url='/pages/businessEnter/index'></ToLogin>
        <AtInput
        name='value1'
        title='姓名'
        type='text'
        placeholder='请输入商户姓名'
        value={value1}
        onChange={onChange1}
      />
      <AtInput
        name='value2'
        title='联系方式'
        type='number'
        placeholder='请输入商户联系方式'
        value={value2}
        onChange={onChange2}
      />
      <AtInput
        name='value3'
        title='商户名称'
        type='text'
        placeholder='请输入商户名称'
        value={value3}
        onChange={onChange3}
      />
      <AtInput
        name='value4'
        title='地址'
        type='text'
        placeholder='请输入地址'
        value={value4}
        onChange={onChange4}
      />
        <AtButton className='submit' onClick={onSubmit} type='primary' >提交</AtButton>

    </View>
  )
}
